<?php
@session_start();
require_once("config/connection.php");
require_once('utils/CommonUtils.php');
require_once('utils/DBUtils.php');
require_once('application/model/BaseDAO.php');
require_once('utils/Constants.php');
require("lib/core/Session.php");
require("lib/core/Object.php");
require("lib/core/Authentication.php");
$commonUtils = new CommonUtils();

$onlineUser = Session::get('fullname');
if($onlineUser != null)
	$commonUtils->redirect("index.php");
	
$action = $commonUtils->getParameter("action");
$username = isset($_POST["j_username"]) ? $_POST["j_username"] : '';
$password = isset($_POST["j_password"]) ? $_POST["j_password"] : '';
if (isset($action) && $action == 'login') {
	$authed = new Authentication();
	$res = $authed->login($username, $password);
	if ($res == LOGIN_SUCC) {
		$commonUtils->redirect("index.php");
	}else if($res == NOT_ACTIVIATED){
		$messageError = "0";
	}else{
		$messageError = "1";
	}
}else if ($action == 'logout') {
	$authed = new Authentication();
	$authed->logout();
}
?>
<html>

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
	<title>Website Quản Lý Nhà Thuốc Theo Chuẩn GPP</title>
	<link rel="stylesheet" type="text/css" href="css/login.css"/>
<style type="text/css">
<!--
a {
	font-family: Tahoma;
	font-size: 12px;
	color: #1258a0;
}
a:visited {
	color: #1258A0;
}
a:hover {
	color: #FF9900;
}
a:active {
	color: #1258A0;
}

.button_login {
	background-image: url('css/images/dn.jpg');
	background-position: left;
	background-repeat: no-repeat; 
	background-color:#ecf9ff; 
	padding-left: 28px;
	height:30px;
	border: 1px solid;
	border-color: #c63 #930 #930 #c63;
	filter:progid:DXImageTransform.Microsoft.Gradient 
	(GradientType=0,StartColorStr='#ffffffff',EndColorStr='#ffeeddaa'); 
}

-->
</style>
<script language="javascript">
function validateForm() {
	if (document.forms[0].j_username.value == '') {
		alert("Nhập tài khoản đăng nhập của bạn.");
		document.forms[0].j_username.focus();
		return false;
	}
	if (document.forms[0].j_password.value == '') {
		alert("Nhập mật khẩu truy cập của bạn.");
		document.forms[0].j_password.focus();
		return false;
	}
	return true;
}

function doSubmit() {
	if(validateForm()) {
		document.forms[0].submit();
	}
}

window.onload = function(){
	document.forms[0].j_username.focus();
}
</script>
</head>
<center>
<body>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post" name="formlogin" onsubmit="return validateForm();">
<div class="cont">
	<div class="banner" style="color:#FFF;text-transform: uppercase;font-size: 20px;font-weight: bold; font-family: Tahoma; vertical-align: bottom;">Website Quản Lý Nhà Thuốc Theo Chuẩn GPP</div>
	<div class="noidung">
		<div class="nd1"></div>
		<div class="nd2">
			<div class="dn">
				<div class="dn1">
					<div class="dn11">
						<div style="width:100%; height:35px;">
							<div align="right" style="width:123px; height:35px; float:left; line-height:20px">Tên đăng nhập </div>
							<div  style="width:240px; height:35px; float:right"><input name="j_username" type="text" autocomplete=off style="width:230px" /></div>
						</div>
						<div style="width:100%; height:35px;">
							<div align="right" style="width:123px; height:35px; float:left; line-height:20px">Mật khẩu </div>
							<div  style="width:240px; height:35px; float:right"><input name="j_password" autocomplete=off type="password" style="width:230px" />
							</div>
						</div>
						<div style="width:100%; height:28px; padding-top:20px">
							<div  style="width:263px; height:28px; float:right">
								<div align="left" style="width:110px; height:27px; line-height:27px; float:right; "><input type="submit" value="Đăng nhập" class="button_login" /></div>
							</div>
						</div>
						<input type="hidden" name="action" value="login"> 
						<div style="color:red;line-height:26px">
							<?php if (isset($messageError)) {?>
				             	<?php if($messageError == 1){?>               
						            <div style="color:red;">
						                Đăng nhập không thành công, Tên đăng nhập hoặc mật khẩu không đúng<br /><br />
						            </div>
					            <?php }else if($messageError == 0){?>
					            	<div style="color:red;">
						                Đăng nhập không thành công, Tài khoản này hiện đang bị khóa<br /><br />
						            </div>
					            <?php }?>
				            <?php }?>
						</div>
					</div>
				</div>
				<div class="dn2"></div>
			</div>
		</div>
		<div class="nd3"></div>
	</div>
	<div align="right" style="width:100%; height:20px; font-family:Tahoma; color:#FFFFFF; font-size:12px; line-height:20px;">&copy;2011 By <a href="http://vietrool.appspot.com" style="color:white;">VietRool</a></div>
</div>
</form>
</body>
</center>
</html>
